package org.sao.security.core.validate.code.sms;


import org.apache.commons.lang.RandomStringUtils;
import org.sao.security.core.properties.SecurityProperties;
import org.sao.security.core.validate.code.ValidateCodeGenerator;
import org.sao.security.core.validate.code.sms.ValidateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.ServletWebRequest;

@Component("smsCodeGenerator")
public class SmsCodeGenerator implements ValidateCodeGenerator {

	
    @Autowired
	private SecurityProperties securityProperties;
	
	@Override
	public ValidateCode generator(ServletWebRequest req) {
		// TODO Auto-generated method stub
	  String code =RandomStringUtils.randomNumeric(securityProperties.getCode().getSms().getLength());
		return new ValidateCode(code,securityProperties.getCode().getSms().getExpireIn());	  
	}

	
}
